
loadList();
async function loadList(){
    let uid = localStorage.getItem("uid");
    let pagenum = 0;
    let pagesize = 10;
    let {data} = await axios.get(proudtListAPI, {
        params: {pagesize, pagenum, uid}
    });
    console.log(data);
    let listArr = data.data;
    let resArr = listArr.map(pObj => `
        <div class="img-box">
            <img src="${pObj.pimg}" alt="">
            <p class="box-tit">${pObj.pname}</p>
            <p class="box-des">${pObj.pdesc}</p>
            <span class="box-price">￥${pObj.pprice}</span>
            <button data-pid="${pObj.pid}" class="cart purchase">立即购买</button>
            <a href="02cartList.html?pid=${pObj.pid}" class="cart-list">了解详情</a>
        </div> 
    `)
    console.log(resArr);
    console.log(resArr.join(""));
    let listProduct = document.querySelector(".list-product")
    listProduct.innerHTML = resArr.join("");

    let cartAddBtns = document.querySelectorAll(".cart");
    console.log(cartAddBtns);
    for(let i = 0; i < cartAddBtns.length; i++){
        cartAddBtns[i].onclick = function(){
            console.log(this);
            let pid = this.getAttribute("data-pid");
            console.log(pid);
            cartAdd();
            async function cartAdd(){
                let pnum = 1;
                let params = {pid, uid, pnum};
                let {data}= await axios.get(cartAddAPI, {params});
                console.log(data);
                alert("加入购物车成功");
                location.href="03productCart.html"
            }
        }
    }
}
